package cn.shujuhai.common.config;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import cn.shujuhai.common.service.SysUserService;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

@Component
public class StpInterfaceImpl implements StpInterface {
    final SysUserService sysUserService;

    public StpInterfaceImpl(SysUserService sysUserService) {
        this.sysUserService = sysUserService;
    }

    /**
     * 获取权限列表
     *
     * @param loginId
     * @param loginType
     * @return
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        if (loginType.equals(StpUtil.TYPE)) {
            Long userId = Long.parseLong(loginId.toString());
            return sysUserService.getPermissionList(userId);
        }
        return Collections.emptyList();
    }

    /**
     * 获取角色列表
     *
     * @param loginId
     * @param loginType
     * @return
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        if (loginType.equals(StpUtil.TYPE)) {
            Long userId = Long.parseLong(loginId.toString());
            return sysUserService.getRoleList(userId);
        }
        return Collections.emptyList();
    }
}